package com.mifengs.mall.floor;

import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.annotation.ItemProviderTag;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.mifengs.mall.R;
import com.mifengs.mall.adapter.FourGridtemAdapter;
import com.mifengs.mall.entity.AdvertBean;
import com.mifengs.mall.entity.FloorBean;
import com.mifengs.mall.util.ToIntentUtil;

import java.util.List;

/**
 * Created by lynn on 2018/4/19.
 */
@ItemProviderTag(
        viewType = FloorListAdapter.TYPE_ELEVEN,
        layout = R.layout.fragment_four_flo
)
public class FloorElevenItemProvider extends BaseItemProvider<FloorBean,BaseViewHolder> {

    private FourGridtemAdapter mFourGridtemAdapter;

    @Override
    public void convert(BaseViewHolder viewHolder, FloorBean floorBean, int i) {
        RecyclerView mRecyclerView = viewHolder.getView(R.id.four_grid_list);
        if(floorBean !=null){
            final List<AdvertBean> advertBeanList = floorBean.getAdverts();
            mRecyclerView.setLayoutManager(new GridLayoutManager(mContext,4));
            mRecyclerView.setNestedScrollingEnabled(false);
            mFourGridtemAdapter= new FourGridtemAdapter(R.layout.item_four_floor,advertBeanList,mContext);
            mRecyclerView.setAdapter(mFourGridtemAdapter);
            mFourGridtemAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
                @Override
                public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                    AdvertBean adverts = advertBeanList.get(position);
                    ToIntentUtil.toCommonIntent(adverts.getActionUrl(),mContext);
                }
            });
        }
    }

    @Override
    public void onClick(BaseViewHolder baseViewHolder, FloorBean floorBean, int i) {

    }

    @Override
    public boolean onLongClick(BaseViewHolder baseViewHolder, FloorBean floorBean, int i) {
        return false;
    }
}
